#include "TemplatexPLClass.h"

TemplatexPLClass::TemplatexPLClass()
{
    name = "";
    allowCommand = false;
    allowTrigger = false;
    allowStatus = false;
}

TemplatexPLClass::TemplatexPLClass(const QString &name)
{
    this->name = name;
    allowCommand = false;
    allowTrigger = false;
    allowStatus = false;
}

TemplatexPLClass::TemplatexPLClass(const QString &name, bool allowCommand, bool allowTrigger, bool allowStatus)
{
    this->name = name;
    this->allowCommand = allowCommand;
    this->allowTrigger = allowTrigger;
    this->allowStatus = allowStatus;
}

TemplatexPLClass::TemplatexPLClass(const QString &name, bool allowCommand, bool allowTrigger, bool allowStatus,
                                   const QList<TemplatexPLItem> &itemList)
{
    this->name = name;
    this->allowCommand = allowCommand;
    this->allowTrigger = allowTrigger;
    this->allowStatus = allowStatus;
    this->itemList = itemList;
}

TemplatexPLClass::TemplatexPLClass(const TemplatexPLClass &other)
{
    this->name = other.name;
    this->allowCommand = other.allowCommand;
    this->allowTrigger = other.allowTrigger;
    this->allowStatus = other.allowStatus;
    this->itemList = other.itemList;
}

TemplatexPLClass::~TemplatexPLClass()
{

}

TemplatexPLClass& TemplatexPLClass::operator =(const TemplatexPLClass& other)
{
    this->name = other.name;
    this->allowCommand = other.allowCommand;
    this->allowTrigger = other.allowTrigger;
    this->allowStatus = other.allowStatus;
    this->itemList = other.itemList;
    return *this;
}

bool TemplatexPLClass::equals(const TemplatexPLClass &other) const
{
    return (this->name == other.name && this->allowCommand == other.allowCommand
            && this->allowStatus == other.allowStatus && this->allowTrigger == other.allowTrigger
            && this->itemList == other.itemList);
}

QString TemplatexPLClass::toString() const
{
    return this->toXml();
}

QString TemplatexPLClass::toXml() const
{
    QString rslt = "<class name=\"%1\" command=\"%2\" status=\"%3\" trigger=\"%4\">\n";
    for(int i = 0; i < itemList.count(); i++)
        rslt += "\t"+itemList.at(i).toXml();
    rslt += "</class>";
    return rslt.arg(name).arg(allowCommand).arg(allowStatus).arg(allowTrigger);
}

bool operator==(const TemplatexPLClass& a, const TemplatexPLClass& b)
{
    return a.equals(b);
}

bool operator!=(const TemplatexPLClass& a, const TemplatexPLClass& b)
{
    return !a.equals(b);
}
